#include<iostream>
#include<pthread.h>
#include<vector>
#include<time.h>
#include<functional>
#include<string>

#include<unistd.h>
int count=0;
class ThreadReturn
{
    public:
    ThreadReturn(std::string name,pthread_t id)
    :_name(name)
    ,_tid(id)
    {}
    static void *ThreadRoutine(void*args)
    {
        ThreadReturn*tr=static_cast<ThreadReturn*>(args);
        tr->Print();
        std::cout<<"陈陈陈陈陈"<<std::endl;
    }
    void Print()
    {
        
        std::cout<<"111111111111111111111111111111111111111"<<std::endl;
    }
    void Run()
    {
        pthread_t tid;
        ThreadReturn *tr;
        pthread_create(&tid,nullptr,ThreadRoutine,tr);
        void*ret=nullptr;
        pthread_join(tid,&ret);
      
        std::cout<<static_cast<int*>(ret)<<std::endl;
    }
    public:
    std::string _name;
    pthread_t _tid;
};
void* thread_run(void*tid) 
{ 
    char id[64];
    for (int i=0;i<5;i++) { 
        count++; 
        printf("The thread_run method count is = %d\n",count); 
        
         snprintf(id,50,"The thread_run method count is = %d\n",count);
    } 
    ThreadReturn *tr=new ThreadReturn(id,pthread_self());
    return tr;
} 
template<class T>
T Int(int x)
{
    return 1+x;
}
int main() 
{ 
//     pthread_t tid; 
//     pthread_create(&tid, NULL, thread_run,(void*)tid);
//     //pthread_detach(tid);
//     // 加入pthread_join后，主线程"main"会一直等待直到tid这个线程执行完毕自己才结束 
//     // 一般项目中需要子线程计算后的值就需要加join方法 
//     void*ret=nullptr;
//     int n=pthread_join(tid,&ret); 
//   std::cout<<"Main Thread Done N:"<<n<<std::endl;
//     // 如果没有join方法可以看看打印的顺序 
//     printf("The count is = %d\n",count); 
//     ThreadReturn *tr=static_cast<ThreadReturn*>(ret);
//     std::cout<<tr->_name<<tr->_tid<<std::endl;
//    tr->Run();
//     getchar(); 
    std::cout<<Int<double>(4)/2<<std::endl;
//     return 0; 
}